# Definition for singly-linked list.
# class ListNode(object):
#     def __init__(self, x):
#         self.val = x
#         self.next = None

class Solution(object):
    def merge(self, l1, l2):
        """
        :type l1: ListNode
        :type l2: ListNode
        :rtype: ListNode
        """
        if l1 == None and l2 == None:
            return None
        elif l1 == None and l2 != None:
            return l2
        elif l1 != None and l2 == None:
            return l1
            
        b1, b2 = l1, l2
        valArr = []
        while True:
            if b1 == None:
                break
            else :
                valArr.append(b1.val)
                b1 = b1.next
        while True:
            if b2 == None:
                break
            else:
                valArr.append(b2.val)
                b2 = b2.next
        
        if len(valArr) == 0 :
            return None
            
        for i in range(len(valArr)-1):
            for j in range(i+1, len(valArr)):
                if valArr[i] > valArr[j]:
                    valArr[i], valArr[j] = valArr[j], valArr[i]
        
        b1 = l1
        while True :
            if b1.next == None :
                b1.next = l2
                break
            else:
                b1 = b1.next
        b1 = l1
        for i in range(len(valArr)):
            b1.val = valArr[i]
            b1 = b1.next
        return l1